<?php

class TransactionModel extends CommonModel {
	protected $tableName = 'tran_record';
	protected $_validate = array(
		array('name','require',''),
		);
		
	protected $_auto	 =	 array(
		array('status','1',self::MODEL_INSERT),
            
		array('create_time','time',self::MODEL_INSERT,'function'),
		);
	
	function setBizZoneActions($bizId,$zonsList)
	{

		if(empty($zonsList)) {
			
		}
                         $where = 'id in('.$zonsList.')';
		
		 
		
                                      
		$rs = $this->db->execute('UPDATE '.$this->tablePrefix.'zone SET bizid='.$bizId.'  WHERE '.$where);
		if($result===false) {
			return false;
		}else {
                                            
                                            
                                            return true;
		}
	}
        function addPropertyRecord($data){
                        $pmodel = D('OtherRecord');
                         if (false === $pmodel->create()) {
                                $this->error($pmodel->getError());
                        }else{
                            $result =$pmodel->add($data);
                        }
                        /*$result = $this->db->execute('INSERT INTO '.$this->tablePrefix.'other_record ( paytype, bizid, placenum, z_price,mon) '
                                                .'VALUES ('.$data['paytype'].','.$data['bizid'].','.$data['placenum'].','.$data['z_price'].','.$data['mon'].') ');
                          
                         */   
                             if($result===false) {
                                    return false;
                            }else {
                              
                              return $result;
                           }
        }

                                      //更新最后月份信息
        function updatePhdate($bizid,$pdate,$hdate){
                          //更新最后月份信息
                        $str="";
                        /*if($paydate!=0){
                               $str .="  p_update=".$paydate.",";
                          }*/
                          if($pdate!=0){
                               $str .="  p_update=".$pdate.",";
                          }
                          if($hdate!=0){
                               $str .="  h_update=".$hdate.",";
                          }
                         $str = substr($str,0,-1);
                          $rs = $this->db->execute('UPDATE '.$this->tablePrefix.'biz SET '.$str.'  WHERE id='.$bizid);
                          if($rs===false) {
                                    return false;
                           }else {
                              return true;
                           }
                          
                      }
              //更新缴费记录ID
          function updatePayFlag($bizid,$mon,$resid,$trid){
                          //更新最后月份信息
                                $str="  1=1 ";
                         if($resid!=0){
                               $str .=" AND resid=".$resid;
                          }
                          if($bizid!=0){
                               $str .="  AND bizid=".$bizid;
                          }
                          if($mon!=0){
                               $str .="  AND meterMon=".$mon;
                          }
                          $rs = $this->db->execute('UPDATE '.$this->tablePrefix.'meter_record SET payflag='.$trid.'  WHERE '.$str);
                          if($rs===false) {
                                    return false;
                           }else {
                              return true;
                           }
                          
          }
                       //更新缴费多条记录ID
          function updatePaysFlag($bizid,$trid,$list){
                          //更新最后月份信息
                                $str="  1=1 ";
                          if($bizid!=0){
                               $str .="  AND bizid=".$bizid;
                          }
                          if(trim($list)<>""){
                                $str .="  AND id in ( ".$list.")";
                          }
                          $rs = $this->db->execute('UPDATE '.$this->tablePrefix.'meter_record SET payflag='.$trid.'  WHERE '.$str);
                          if($rs===false) {
                                    return false;
                           }else {
                              return true;
                           }
                          
          } 
          //更新月统计信息
          function updateStatistics($zoneid,$plist){
              $recordmon = $this->db->query('SELECT meterMon FROM '.$this->tablePrefix.'meter_record WHERE id IN ('. $plist. ')');
              if(sizeof($recordmon)>0){
                 
                    $rs = $this->db->execute('UPDATE '.$this->tablePrefix.'record_statistics SET paynum=paynum+1 WHERE zoneid='.$zoneid.' AND mondate in ('. implode(',',$recordmon).')');
                    if($rs===false) {
                        return false;
                    }else {
                        return true;
                    }
              }
          }





}
?>